﻿using Pretext.Functions;
using System.Collections.Generic;

namespace Pretext.Parsers {
    public class FunctionalityParser : Parser {

        public bool SeekNextFunction() {

            // keep going until the next token is 
            while (NextToken != null && !NextToken.Is(TokenType.OpeningArgumentBracket)) {
                if (!SeekNextToken(TokenType.Symbol)) break;
            }

            if (NextToken == null) return false;

            return (CurrentToken.Is(TokenType.Symbol) && NextToken.Is(TokenType.OpeningArgumentBracket));

        }

        public FunctionInfo GetFunctionInfo() {

#if DEBUG
            if (!CurrentToken.Is(TokenType.Symbol))
                throw new FunctionParserException("Can not call GetFunctionInfo() unless the parser position is at a Symbol.");
#endif

            string functionName = CurrentToken.Value;
            int startIndex = CurrentPosition;

            List<Token> arguments = GetArguments();

            int endIndex = CurrentPosition;

            return new FunctionInfo(functionName, arguments, startIndex, endIndex);

        }

        public override void ParseAllTokens() {

            while (SeekNextFunction()) {

                FunctionInfo info = GetFunctionInfo();

                switch (info.FunctionName) {

                    case "write":

                        

                        break;

                }

            }

        }

    }
}